package org.benjamin.lending.controller;

import org.benjamin.lending.domain.entity.BorrowInfo;
import org.benjamin.lending.domain.entity.BorrowInfo.Status;
import org.benjamin.lending.domain.form.BorrowIndex;
import org.benjamin.lending.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping
public class HomeController {
	
	@Autowired
	private BorrowService borrowService;
	
	@RequestMapping(value = {"index",""})
	public String index(ModelMap modelMap) {
		Pageable pageable = new PageRequest(0, 10);
		BorrowIndex borrowIndex = new BorrowIndex();
		borrowIndex.getStatus().add(Status.FINISH);
		borrowIndex.getStatus().add(Status.RELEASE);
		Page<BorrowInfo> borrowInfos = this.borrowService.findBorrowPage(borrowIndex, pageable);
		modelMap.addAttribute("borrowInfos",borrowInfos);
		return "index";
	}
	
	@RequestMapping(value = {"manager/index","manager"})
	public String adminIndex() {
		return "admin.index";
	}

}
